/**
 * 文件名：****.java
 * 版权：Copyright Lightkit All Rights Reserved.
 * 描述：*****
 */
package com.lightkits.wms.domain.stocktransfer;

import com.lightkits.framework.common.model.CheckResult;
import com.lightkits.framework.common.utility.object.ObjectUtil;
import com.lightkits.framework.soa.hzero.executor.ServiceExecutor;
import com.lightkits.wms.domain.stocktransfer.service.MiscellAdjustDomain;
import com.lightkits.wms.dto.stocktransfer.MiscellAdjustRequestType;
import com.lightkits.wms.dto.stocktransfer.MiscellAdjustResponseType;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * MiscellAdjustExecutor
 *
 * @author jing.wei@hand-china.com
 * Created on 2019/4/24 12:08
 */
@Component
public class MiscellAdjustExecutor implements
        ServiceExecutor<MiscellAdjustRequestType, MiscellAdjustResponseType> {
    private final MiscellAdjustDomain miscellAdjustDomain;

    /**
     * 杂项调整服务
     *
     * @param miscellAdjustDomain 杂项调整参数
     * @return
     **/
    @Autowired
    public MiscellAdjustExecutor(MiscellAdjustDomain miscellAdjustDomain) {
        this.miscellAdjustDomain = miscellAdjustDomain;
    }

    @Override
    public MiscellAdjustResponseType service(MiscellAdjustRequestType request) {
        MiscellAdjustResponseType response = new MiscellAdjustResponseType();
        response.setSuccessful(true);

        CheckResult<String> result = miscellAdjustDomain.misCellAdjust(request.getMiscellAdjust());
        if (!result.isSuccessful() || ObjectUtil.isNullOrEmpty(result.getData())) {
            return result.fill(response);
        }
        response.setOnhandQuantity(result.getData());
        result.fill(response);

        return response;
    }
}
